package com.linwen.excise.leetcode;

import java.lang.reflect.Modifier;

/**
 * @ClassName _1576替换所有的问号
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/7 2:07 AM
 * @Version 1.0
 */
public class _1576替换所有的问号 {
    public static void main(String[] args) {
        String s = "?zs";
        System.out.println(modifyString(s));
    }

    public static String modifyString(String s) {
        if(!s.contains("?")){
            return s;
        }
        char[] charArray = s.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if(c=='?'){
                for (char ch = 'a'; ch <= 'c'; ++ch) {
                    if ((i > 0 && charArray[i - 1] == ch) || (i < charArray.length - 1 && charArray[i + 1] == ch)) {
                        continue;
                    }
                    charArray[i] = ch;
                    break;
                }

            }
        }
        return new String(charArray);
    }

}
